package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.OrderBean;
import com.project.bean.RefundOrderBean;
import com.project.mapper.IOrderMapper;
import com.project.mapper.IRefundOrderMapper;
import com.project.service.IRefundOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class RefundOrderServiceImpl implements IRefundOrderService {
      @Autowired
      private IRefundOrderMapper refundOrderMapper;
      @Autowired
      private IOrderMapper orderMapper;
      @Override
      public List<RefundOrderBean> findByUserNum(Long userNum) {
            QueryWrapper<OrderBean> qw1=new QueryWrapper<>();
            qw1.eq("userNum",userNum);
            List<OrderBean> list1=orderMapper.selectList(qw1);
            List<RefundOrderBean> list2=new ArrayList<>();
            list1.forEach(n->{
                  QueryWrapper<RefundOrderBean> qw2=new QueryWrapper<>();
                  qw2.eq("ret_id",n.getOrderNum());
                  RefundOrderBean refundOrderBean=refundOrderMapper.selectOne(qw2);
                  if(refundOrderBean!=null){
                        list2.add(refundOrderBean);
                  }
            });
            return list2;
      }
      
      @Override
      public void add(RefundOrderBean refundOrderBean) {
            refundOrderMapper.insert(refundOrderBean);
      }
}
